package com.chookss.tiku.adapter

import android.graphics.Color
import com.chookss.R
import com.chookss.tiku.entity.LeftEntiry
import com.johnrambo.ktea.base.LiteAdapter
import com.johnrambo.ktea.ktExtends.onclick
import kotlinx.android.synthetic.main.item_left.view.*


class LeftListAdapter : LiteAdapter<LeftEntiry>(R.layout.item_left) {
    var listener: ((LeftEntiry) -> Unit)? = null

    override fun onBindViewHolder(holder: VH, position: Int) {
        val entity = datas[position]
        holder.itemView.run {
            tvLeft.text = entity.catalogName
            if (entity.isSelected == true) tvLeft.setBackgroundColor(Color.parseColor("#ffffff")) else tvLeft.setBackgroundColor(Color.parseColor("#f7f7f7"))
            onclick {

                for (data in datas) {
                    data.isSelected = false
                }
                datas[position].isSelected = true
                notifyDataSetChanged()
                listener?.let {
                    it(entity)
                }

            }
        }
    }

    //override fun getItemCount() = max(datas.size, 4)
}